import React,{useEffect} from 'react'
import { Button, Input, Form } from 'react-vant'
import axios from "../utils/axios"
import {useNavigate } from "react-router-dom"
export default () => {
  const [form] = Form.useForm()
  const navigate  =useNavigate()
  useEffect(()=>{
    window.localStorage.clear()
  },[])
  const onFinish = values => {
      axios.get("/api/login",{
          params:values
      }).then(res=>{
          console.log(res.data);
          if (res.data.code === 1) {
            window.localStorage.setItem("token",res.data.token)
             navigate("/my")
          }
        
      })
  }

  return (
    <Form
      form={form}
      onFinish={onFinish}
      footer={
        <div style={{ margin: '16px 16px 0' }}>
          <Button round nativeType='submit' type='primary' block>
            登陆
          </Button>
        </div>
      }
    >
      <Form.Item
        intro='确保这是唯一的用户名'
        rules={[{ required: true, message: '请填写用户名' }]}
        name='username'
        label='用户名'
      >
        <Input placeholder='请输入用户名' />
      </Form.Item>
      <Form.Item
        rules={[{ required: true, message: '请填写密码' }]}
        name='password'
        label='密码'
      >
        <Input placeholder='请输入密码' />
      </Form.Item>
    </Form>
  )
}
